package com.datastructure.test.longestmountain;

import java.util.ArrayList;

public class LongestMountain {

    public static void main(String[] args) {
        LongestMountain longestMountain = new LongestMountain();
        ArrayList<Integer> nums = new ArrayList<>();
        nums.add(2);
        nums.add(5);
        nums.add(2);
        nums.add(1);
        nums.add(5);
        int longestmountain = longestMountain.longestmountain(nums);
        System.out.println(longestmountain);
    }

    public int longestmountain (ArrayList<Integer> nums) {
        // write code here
        int max = 0;
        for (int i = 0; i < nums.size()-1; i++) {
            if(nums.get(i)<nums.get(i+1)){
                max=Math.max(max,computeLongestMountain(i,nums));
            }
        }
        return max;
    }

    private int computeLongestMountain(int start, ArrayList<Integer> nums) {
        int max = 0;
        int i=start;
        for (; i < nums.size()-1; i++) {
            if(nums.get(i)< nums.get(i+1)){
                max++;
            } else {
                break;
            }
        }
        for (int j = i; j < nums.size()-1; j++) {
            if(nums.get(j)> nums.get(j+1)){
                max++;
            } else {
                break;
            }
        }
        max++;
        if(max>2){
            return max;
        }else {
            return 0;
        }
    }
}
